/*********************************************************************
*                                                                    *
*                SEGGER Microcontroller GmbH & Co. KG                *
*        Solutions for real time microcontroller applications        *
*                                                                    *
**********************************************************************
*                                                                    *
* C-file generated by:                                               *
*                                                                    *
*        GUI_Builder for emWin version 5.44                          *
*        Compiled Nov 10 2017, 08:53:57                              *
*        (c) 2017 Segger Microcontroller GmbH & Co. KG               *
*                                                                    *
**********************************************************************
*                                                                    *
*        Internet: www.segger.com  Support: support@segger.com       *
*                                                                    *
**********************************************************************
*/

// USER START (Optionally insert additional includes)
#include "Floor1Control.h"
#include "Floor2Control.h"
#include "Floor3Control.h"
// USER END

#include "DIALOG.h"
#include "stdio.h"



/*********************************************************************
*
*       Defines
*
**********************************************************************
*/
#define ID_WINDOW_0            (GUI_ID_USER + 0x00)
#define ID_TEXT_0            (GUI_ID_USER + 0x01)
#define ID_TEXT_1            (GUI_ID_USER + 0x02)
#define ID_TEXT_2            (GUI_ID_USER + 0x03)
#define ID_TEXT_3            (GUI_ID_USER + 0x04)
#define ID_TEXT_4            (GUI_ID_USER + 0x05)
#define ID_TEXT_5            (GUI_ID_USER + 0x06)
#define ID_TEXT_6            (GUI_ID_USER + 0x07)
#define ID_EDIT_0            (GUI_ID_USER + 0x08)
#define ID_EDIT_1            (GUI_ID_USER + 0x09)
#define ID_EDIT_2            (GUI_ID_USER + 0x0A)
#define ID_BUTTON_00            (GUI_ID_USER + 0x0B)
#define ID_BUTTON_01            (GUI_ID_USER + 0x0C)
#define ID_BUTTON_02            (GUI_ID_USER + 0x0D)

#define ID_WINDOW_1		(GUI_ID_USER + 0x0E)
#define ID_TEXT_7		(GUI_ID_USER + 0x0F)
#define ID_BUTTON_0		(GUI_ID_USER + 0x10)
#define ID_BUTTON_1		(GUI_ID_USER + 0x11)
#define ID_BUTTON_2		(GUI_ID_USER + 0x12)
#define ID_BUTTON_3		(GUI_ID_USER + 0x13)
#define ID_BUTTON_4		(GUI_ID_USER + 0x14)
#define ID_BUTTON_5		(GUI_ID_USER + 0x15)
#define ID_BUTTON_6		(GUI_ID_USER + 0x16)
#define ID_BUTTON_7		(GUI_ID_USER + 0x17)
#define ID_BUTTON_8		(GUI_ID_USER + 0x18)
#define ID_BUTTON_9		(GUI_ID_USER + 0x19)
#define ID_BUTTON_10	(GUI_ID_USER + 0x1A)
#define ID_BUTTON_11	(GUI_ID_USER + 0x1B)
#define ID_BUTTON_12	(GUI_ID_USER + 0x1C)
#define ID_EDIT_3		(GUI_ID_USER + 0x1D)
#define ID_TEXT_8		(GUI_ID_USER + 0x1E)
#define ID_TEXT_9		(GUI_ID_USER + 0x1F)


// USER START (Optionally insert additional defines)
extern GUI_CONST_STORAGE GUI_FONT GUI_Font48;
extern GUI_CONST_STORAGE GUI_FONT GUI_Font60;
WM_HWIN CreateSubWindow(GUI_HWIN hParent);
WM_HWIN CreateWindow(void);

#define MY_MESSAGE_DAI_TYPE		WM_USER + 0x00
#define MY_MESSAGE_DISP_TYPE	WM_USER + 0x01
#define TEMP_TYPE		0
#define O2_TYPE			1
#define CO2_TYPE		2
// USER END

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/

// USER START (Optionally insert additional static data)
static WM_MESSAGE _dialogMessage;
static WM_MESSAGE _dialogDispMessage;
static float _dispValue;
static float _dispValue2;
static float _dispValue3;
char disp_buf[10];
GUI_HWIN disp_text_item;
WM_HWIN _hWin;
GUI_COLOR _default_button_color;
// USER END

/*********************************************************************
*
*       _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 800, 480, 0, 0x0, 0 },

    { TEXT_CreateIndirect, "TextTemp", ID_TEXT_0, 30, 50, 140, 60, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Button1", ID_BUTTON_00, 670, 50, 100, 60, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "TextO2", ID_TEXT_3, 350, 50, 100, 60, 0, 0x64, 0 },
    { EDIT_CreateIndirect, "EditTemp", ID_EDIT_0, 160, 40, 190, 80, 0, 0x64, 0 },
    { EDIT_CreateIndirect, "Edit", ID_EDIT_1, 450, 40, 190, 80, 0, 0x64, 0 },

    { TEXT_CreateIndirect, "TextTime2", ID_TEXT_1, 30, 370, 140, 60, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "Text2", ID_TEXT_5, 160, 360, 150, 80, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Button2", ID_BUTTON_01, 670, 370, 100, 60, 0, 0x0, 0 },

    { TEXT_CreateIndirect, "TextTime3", ID_TEXT_2, 30, 210, 140, 60, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "TextCO2", ID_TEXT_4, 350, 210, 100, 60, 0, 0x64, 0 },
    { TEXT_CreateIndirect, "Text3", ID_TEXT_6, 160, 200, 150, 80, 0, 0x0, 0 },
    { EDIT_CreateIndirect, "Edit", ID_EDIT_2, 450, 200, 190, 80, 0, 0x64, 0 },
    { BUTTON_CreateIndirect, "Button3", ID_BUTTON_02, 670, 210, 100, 60, 0, 0x0, 0 },
    // USER START (Optionally insert additional widgets)
    // USER END
};

/*********************************************************************
*
*       _aSubDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aSubDialogCreate[] = {
    { WINDOW_CreateIndirect, "Window", ID_WINDOW_1, 0, 0, 800, 480, 0, 0x0, 0 },

    { BUTTON_CreateIndirect, "Button1", ID_BUTTON_1, 30, 100, 240, 80, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Button2", ID_BUTTON_2, 280, 100, 240, 80, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Button3", ID_BUTTON_3, 530, 100, 240, 80, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Button4", ID_BUTTON_4, 30, 190, 240, 80, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Button5", ID_BUTTON_5, 280, 190, 240, 80, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Button6", ID_BUTTON_6, 530, 190, 240, 80, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Button7", ID_BUTTON_7, 30, 280, 240, 80, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Button8", ID_BUTTON_8, 280, 280, 240, 80, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Button9", ID_BUTTON_9, 530, 280, 240, 80, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Buttonp", ID_BUTTON_10, 30, 370, 240, 80, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Button0", ID_BUTTON_0, 280, 370, 240, 80, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Buttonok", ID_BUTTON_11, 530, 370, 240, 80, 0, 0x0, 0 },
    //{ BUTTON_CreateIndirect, "Buttonrst", ID_BUTTON_12, 650, 20, 120, 60, 0, 0x0, 0 },

    { TEXT_CreateIndirect, "Text", ID_TEXT_7, 300, 20, 250, 60, 0, 0x0, 0 },
    { EDIT_CreateIndirect, "Edit", ID_EDIT_3, 550, 20, 160, 60, 0, 0x64, 0 },
    { TEXT_CreateIndirect, "Text%", ID_TEXT_8, 715, 20, 120, 60, 0, 0x64, 0 },
    // USER START (Optionally insert additional widgets)
    { TEXT_CreateIndirect, "Textlast", ID_TEXT_9, 30, 20, 270, 60, 0, 0x64, 0 },
    // USER END
};

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/

// USER START (Optionally insert additional static code)
// USER END

/*********************************************************************
*
*       _cbDialog
*/
static void _cbDialog(WM_MESSAGE* pMsg) {
    WM_HWIN hItem;
    WM_HWIN hwin;
    int     NCode;
    int     Id;
    // USER START (Optionally insert additional variables)
    // USER END

    switch (pMsg->MsgId) {
    case MY_MESSAGE_DISP_TYPE:
        switch (pMsg->Data.v)
        {
        case TEMP_TYPE:
            temp_struct.expect_temp = _dispValue;
//			hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
//			sprintf(disp_buf, "%.1f\xe2\x84\x83", _dispValue);
//			EDIT_SetText(hItem, disp_buf);
            break;
        case O2_TYPE:
            o2_struct.expect_temp = _dispValue2;
//			hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_1);
//			sprintf(disp_buf, "%.1f%%", _dispValue2);
//			EDIT_SetText(hItem, disp_buf);
            break;
        case CO2_TYPE:
            co2_struct.expect_temp = _dispValue3;
//			hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_2);
//			sprintf(disp_buf, "%.1f%%", _dispValue3);
//			EDIT_SetText(hItem, disp_buf);
            break;
        default:
            break;
        }
        break;
    case WM_PAINT:
        GUI_SetColor(GUI_BLACK);
        //GUI_SetBkColor(GUI_GREEN);
        GUI_DrawHLine(160, 0, 800);
        GUI_DrawHLine(320, 0, 800);
        break;
    case WM_INIT_DIALOG:
        //
        // Initialization of 'Window'
        //
        hItem = pMsg->hWin;
        WINDOW_SetBkColor(hItem, 0x00F2F2F2);
        //
        // Initialization of 'TextTemp ??'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
        TEXT_SetText(hItem, "\xe6\xb8\xa9\xe5\xba\xa6:");
        TEXT_SetFont(hItem, &GUI_Font48);
        TEXT_SetTextAlign(hItem, TEXT_CF_LEFT | TEXT_CF_VCENTER);
        //
        // Initialization of 'TextTime2 ??2'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
        TEXT_SetText(hItem, "\xe8\xae\xa1\xe6\x97\xb6:");
        TEXT_SetFont(hItem, &GUI_Font48);
        TEXT_SetTextAlign(hItem, TEXT_CF_LEFT | TEXT_CF_VCENTER);
        //
        // Initialization of 'Text2 ????2'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_5);
        TEXT_SetText(hItem, "00:00");
        TEXT_SetFont(hItem, &GUI_Font60);
        TEXT_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        //
        // Initialization of 'TextTime3 ??3'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
        TEXT_SetText(hItem, "\xe8\xae\xa1\xe6\x97\xb6:");
        TEXT_SetFont(hItem, &GUI_Font48);
        TEXT_SetTextAlign(hItem, TEXT_CF_LEFT | TEXT_CF_VCENTER);
        //
        // Initialization of 'Text3 ????3'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_6);
        TEXT_SetText(hItem, "00:00");
        TEXT_SetFont(hItem, &GUI_Font60);
        TEXT_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        //
        // Initialization of 'TextO2'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_3);
        TEXT_SetText(hItem, "O2:");
        TEXT_SetFont(hItem, &GUI_Font48);
        TEXT_SetTextAlign(hItem, TEXT_CF_RIGHT | TEXT_CF_VCENTER);
        //
        // Initialization of 'TextCO2'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_4);
        TEXT_SetText(hItem, "CO2:");
        TEXT_SetFont(hItem, &GUI_Font48);
        TEXT_SetTextAlign(hItem, TEXT_CF_RIGHT | TEXT_CF_VCENTER);
        //
        // Initialization of 'EditTemp'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
        EDIT_SetText(hItem, "37.0\xe2\x84\x83");
        EDIT_SetFont(hItem, &GUI_Font60);
        EDIT_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        //EDIT_EnableBlink(hItem, 1, 0);
        //
        // Initialization of 'EditO2'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_1);
        EDIT_SetText(hItem, "99.0%");
        EDIT_SetFont(hItem, &GUI_Font60);
        EDIT_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        //EDIT_EnableBlink(hItem, 0, 0);
        //
        // Initialization of 'EditCO2'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_2);
        EDIT_SetText(hItem, "100.0%");
        EDIT_SetFont(hItem, &GUI_Font60);
        EDIT_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        //EDIT_EnableBlink(hItem, 0, 0);
        //
        // Initialization of 'Button1'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_00);
        BUTTON_SetText(hItem, "\xe6\x8a\xa4\xe7\x90\x86");
        BUTTON_SetFont(hItem, &GUI_Font48);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        //
        // Initialization of 'Button2'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_01);
        BUTTON_SetText(hItem, "\xe9\xba\xbb\xe9\x86\x89");
        BUTTON_SetFont(hItem, &GUI_Font48);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        _default_button_color = BUTTON_GetBkColor(hItem, 0);
        //
        // Initialization of 'Button3'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_02);
        BUTTON_SetText(hItem, "\xe5\xae\x89\xe4\xb9\x90");
        BUTTON_SetFont(hItem, &GUI_Font48);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        // USER START (Optionally insert additional code for further widget initialization)

        // USER END
        break;
    case WM_NOTIFY_PARENT:
        Id = WM_GetId(pMsg->hWinSrc);
        NCode = pMsg->Data.v;
        switch (Id) {
        case ID_EDIT_0: // Notifications sent by 'EditTemp'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                _dialogMessage.MsgId = MY_MESSAGE_DAI_TYPE;
                _dialogMessage.hWinSrc = pMsg->hWin;
                hwin = CreateSubWindow(pMsg->hWin);
                _dialogMessage.hWin = hwin;
                _dialogMessage.Data.v = TEMP_TYPE;
                WM_SendMessage(hwin, &_dialogMessage);
                // USER END
                break;
            case WM_NOTIFICATION_VALUE_CHANGED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_EDIT_1: // Notifications sent by 'EditO2'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                _dialogMessage.MsgId = MY_MESSAGE_DAI_TYPE;
                _dialogMessage.hWinSrc = pMsg->hWin;
                hwin = CreateSubWindow(pMsg->hWin);
                _dialogMessage.hWin = hwin;
                _dialogMessage.Data.v = O2_TYPE;
                WM_SendMessage(hwin, &_dialogMessage);
                // USER END
                break;
            case WM_NOTIFICATION_VALUE_CHANGED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_EDIT_2: // Notifications sent by 'EditCO2'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                _dialogMessage.MsgId = MY_MESSAGE_DAI_TYPE;
                _dialogMessage.hWinSrc = pMsg->hWin;
                hwin = CreateSubWindow(pMsg->hWin);
                _dialogMessage.hWin = hwin;
                _dialogMessage.Data.v = CO2_TYPE;
                WM_SendMessage(hwin, &_dialogMessage);
                // USER END
                break;
            case WM_NOTIFICATION_VALUE_CHANGED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_00: // Notifications sent by 'Button1'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
//				ele_valve_change_flag(&ev1);

                if (cs1.state == Wait)
                {
                    set_state(&cs1, Start);
                }
                else
                {
                    set_state(&cs1, Wait);
                }
                if (cs1.state == Start) {
                    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_00);
                    BUTTON_SetBkColor(hItem, 0, 0x0000FF00);
                } else {
                    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_00);
                    BUTTON_SetBkColor(hItem, 0, _default_button_color);
                }

                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_01: // Notifications sent by 'Button2'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                change_state(&cs3);
                if (cs3.state == Start) {
                    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_01);
                    BUTTON_SetBkColor(hItem, 0, 0x0000FF00);
                } else {
                    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_01);
                    BUTTON_SetBkColor(hItem, 0, _default_button_color);
                }
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_02: // Notifications sent by 'Button3'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)

                change_state(&cs2);
                if (cs2.state == Start) {
                    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_02);
                    BUTTON_SetBkColor(hItem, 0, 0x0000FF00);
                } else {
                    hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_02);
                    BUTTON_SetBkColor(hItem, 0, _default_button_color);
                }
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
            // USER START (Optionally insert additional code for further Ids)
            // USER END
        }
        break;
    // USER START (Optionally insert additional message handling)
    // USER END
    default:
        WM_DefaultProc(pMsg);
        break;
    }
}

/*********************************************************************

* cbEdit ??????

*/

static void _cbEdit(WM_MESSAGE * pMsg) {

    switch (pMsg->MsgId) {
    case WM_KEY:
        switch (((WM_KEY_INFO *)(pMsg->Data.p))->Key) {
//        case GUI_KEY_ENTER:
//            price = EDIT_GetFloatValue(widgetsItemBuf[0]);
//            WM_SetFocus(widgetsItemBuf[1]);
//            return;
        case GUI_KEY_BACKSPACE:
            if(((WM_KEY_INFO *)(pMsg->Data.p))->PressedCnt == 1)
                EDIT_SetCursorAtChar(pMsg->hWin,EDIT_GetCursorCharPos(pMsg->hWin) - 1);
            break;
        }
        break;
    }
    EDIT_Callback(pMsg);
}

/*********************************************************************
*
*       _cbSubDialog
*/
static void _cbSubDialog(WM_MESSAGE* pMsg) {
    WM_HWIN hItem;
    int     NCode;
    int     Id;
    // USER START (Optionally insert additional variables)
    int      Pressed;
    // USER END
    Pressed = 1;
    static int dialogType = TEMP_TYPE;

    switch (pMsg->MsgId) {
    case MY_MESSAGE_DAI_TYPE:
        hItem = pMsg->hWin;
        NCode = pMsg->Data.v;
        switch (NCode)
        {
        case TEMP_TYPE:
            dialogType = TEMP_TYPE;
            hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_7);
            TEXT_SetText(hItem, "\xe6\xb8\xa9\xe5\xba\xa6\xe8\xae\xbe\xe5\xae\x9a:");
            TEXT_SetFont(hItem, &GUI_Font48);
            TEXT_SetTextAlign(hItem, TEXT_CF_RIGHT | TEXT_CF_VCENTER);

            hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_3);
            EDIT_SetText(hItem, "100.0");
            EDIT_SetFont(hItem, &GUI_Font48);
            EDIT_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
            EDIT_SetFloatMode(hItem, 37.0f, 0.0f, 60.0f, 1, 0);
            EDIT_SetFloatValue(hItem, _dispValue);

            hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_8);
            TEXT_SetText(hItem, "\xe2\x84\x83");
            TEXT_SetFont(hItem, &GUI_Font48);
            TEXT_SetTextAlign(hItem, TEXT_CF_LEFT | TEXT_CF_VCENTER);

            sprintf(disp_buf, "\xe4\xb8\x8a\xe6\xac\xa1:%.1f\xe2\x84\x83", _dispValue);
            hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_9);
            TEXT_SetText(hItem, disp_buf);
            break;
        case O2_TYPE:
            dialogType = O2_TYPE;
            hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_7);
            TEXT_SetText(hItem, "O2\xe8\xae\xbe\xe5\xae\x9a:");
            TEXT_SetFont(hItem, &GUI_Font48);
            TEXT_SetTextAlign(hItem, TEXT_CF_RIGHT | TEXT_CF_VCENTER);

            hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_3);
            EDIT_SetText(hItem, "100.0");
            EDIT_SetFont(hItem, &GUI_Font48);
            EDIT_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
            EDIT_SetFloatMode(hItem, 0.0f, 0.0f, 100.0f, 1, 0);
            EDIT_SetFloatValue(hItem, _dispValue2);

            hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_8);
            TEXT_SetText(hItem, "%");
            TEXT_SetFont(hItem, &GUI_Font48);
            TEXT_SetTextAlign(hItem, TEXT_CF_LEFT | TEXT_CF_VCENTER);

            sprintf(disp_buf, "\xe4\xb8\x8a\xe6\xac\xa1:%.1f%%", _dispValue2);
            hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_9);
            TEXT_SetText(hItem, disp_buf);
            break;
        case CO2_TYPE:
            dialogType = CO2_TYPE;
            hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_7);
            TEXT_SetText(hItem, "CO2\xe8\xae\xbe\xe5\xae\x9a:");
            TEXT_SetFont(hItem, &GUI_Font48);
            TEXT_SetTextAlign(hItem, TEXT_CF_RIGHT | TEXT_CF_VCENTER);

            hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_3);
            EDIT_SetText(hItem, "100.0");
            EDIT_SetFont(hItem, &GUI_Font48);
            EDIT_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
            EDIT_SetFloatMode(hItem, 0.0f, 0.0f, 100.0f, 1, 0);
            EDIT_SetFloatValue(hItem, _dispValue3);

            hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_8);
            TEXT_SetText(hItem, "%");
            TEXT_SetFont(hItem, &GUI_Font48);
            TEXT_SetTextAlign(hItem, TEXT_CF_LEFT | TEXT_CF_VCENTER);

            sprintf(disp_buf, "\xe4\xb8\x8a\xe6\xac\xa1:%.1f%%", _dispValue3);
            hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_9);
            TEXT_SetText(hItem, disp_buf);
        default:
            break;
        }
        break;
    case WM_INIT_DIALOG:
        //
        // Initialization of 'Window'
        //
        hItem = pMsg->hWin;
        WINDOW_SetBkColor(hItem, 0x00F2F2F2);
        //
        // Initialization of 'Text'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_7);
        TEXT_SetText(hItem, "O2\xe8\xae\xbe\xe5\xae\x9a:");
        TEXT_SetFont(hItem, &GUI_Font48);
        TEXT_SetTextAlign(hItem, TEXT_CF_RIGHT | TEXT_CF_VCENTER);
        //
        // Initialization of 'Text'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_8);
        TEXT_SetText(hItem, "%");
        TEXT_SetFont(hItem, &GUI_Font48);
        TEXT_SetTextAlign(hItem, TEXT_CF_LEFT | TEXT_CF_VCENTER);
        //
        // Initialization of 'Text'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_9);
        TEXT_SetText(hItem, "last");
        TEXT_SetFont(hItem, &GUI_Font48);
        TEXT_SetTextAlign(hItem, TEXT_CF_LEFT | TEXT_CF_VCENTER);
        //
        // Initialization of 'Edit'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_3);
        EDIT_SetText(hItem, "100.0");
        EDIT_SetFont(hItem, &GUI_Font48);
        EDIT_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        EDIT_SetFloatMode(hItem, 0.0f, 0.0f, 100.0f, 1, 0);
        WM_SetCallback (hItem, _cbEdit);
        //EDIT_SetInsertMode(hItem, 1);

        //
        // Initialization of 'Button1'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
        BUTTON_SetText(hItem, "1");
        BUTTON_SetFont(hItem, &GUI_Font60);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        BUTTON_SetFocussable(hItem, 0);
        //
        // Initialization of 'Button2'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
        BUTTON_SetText(hItem, "2");
        BUTTON_SetFont(hItem, &GUI_Font60);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        BUTTON_SetFocussable(hItem, 0);
        //
        // Initialization of 'Button3'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_3);
        BUTTON_SetText(hItem, "3");
        BUTTON_SetFont(hItem, &GUI_Font60);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        BUTTON_SetFocussable(hItem, 0);
        //
        // Initialization of 'Button4'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_4);
        BUTTON_SetText(hItem, "4");
        BUTTON_SetFont(hItem, &GUI_Font60);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        BUTTON_SetFocussable(hItem, 0);
        //
        // Initialization of 'Button5'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_5);
        BUTTON_SetText(hItem, "5");
        BUTTON_SetFont(hItem, &GUI_Font60);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        BUTTON_SetFocussable(hItem, 0);
        //
        // Initialization of 'Button6'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_6);
        BUTTON_SetText(hItem, "6");
        BUTTON_SetFont(hItem, &GUI_Font60);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        BUTTON_SetFocussable(hItem, 0);
        //
        // Initialization of 'Button7'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_7);
        BUTTON_SetText(hItem, "7");
        BUTTON_SetFont(hItem, &GUI_Font60);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        BUTTON_SetFocussable(hItem, 0);
        //
        // Initialization of 'Button8'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_8);
        BUTTON_SetText(hItem, "8");
        BUTTON_SetFont(hItem, &GUI_Font60);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        BUTTON_SetFocussable(hItem, 0);
        //
        // Initialization of 'Button9'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_9);
        BUTTON_SetText(hItem, "9");
        BUTTON_SetFont(hItem, &GUI_Font60);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        BUTTON_SetFocussable(hItem, 0);
        //
        // Initialization of 'Button0'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
        BUTTON_SetText(hItem, "0");
        BUTTON_SetFont(hItem, &GUI_Font60);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        BUTTON_SetFocussable(hItem, 0);
        //
        // Initialization of 'Button10'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_10);
        BUTTON_SetText(hItem, "\xe5\x8f\x96\xe6\xb6\x88");
        BUTTON_SetFont(hItem, &GUI_Font48);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        BUTTON_SetFocussable(hItem, 0);
        //
        // Initialization of 'Buttonok'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_11);
        BUTTON_SetText(hItem, "\xe7\xa1\xae\xe5\xae\x9a");
        BUTTON_SetFont(hItem, &GUI_Font48);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        BUTTON_SetFocussable(hItem, 0);
        //
        // Initialization of 'ButtonDel'
        //
        hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_12);
        BUTTON_SetText(hItem, "Del");
        BUTTON_SetFont(hItem, &GUI_Font48);
        BUTTON_SetTextAlign(hItem, TEXT_CF_HCENTER | TEXT_CF_VCENTER);
        BUTTON_SetFocussable(hItem, 0);
        // USER START (Optionally insert additional code for further widget initialization)
        // USER END
        break;
    case WM_NOTIFY_PARENT:
        Id = WM_GetId(pMsg->hWinSrc);
        NCode = pMsg->Data.v;
        switch (Id) {
        case ID_BUTTON_0: // Notifications sent by 'Button1'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                GUI_SendKeyMsg('0', Pressed);
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_1: // Notifications sent by 'Button2'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                GUI_SendKeyMsg('1', Pressed);
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_2: // Notifications sent by 'Button3'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                GUI_SendKeyMsg('2', Pressed);
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_3: // Notifications sent by 'Button4'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                GUI_SendKeyMsg('3', Pressed);
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_4: // Notifications sent by 'Button5'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                GUI_SendKeyMsg('4', Pressed);
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_5: // Notifications sent by 'Button6'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                GUI_SendKeyMsg('5', Pressed);
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_6: // Notifications sent by 'Button7'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                GUI_SendKeyMsg('6', Pressed);
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_7: // Notifications sent by 'Button8'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                GUI_SendKeyMsg('7', Pressed);
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_8: // Notifications sent by 'Button9'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                GUI_SendKeyMsg('8', Pressed);
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_9: // Notifications sent by 'Buttonp'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                GUI_SendKeyMsg('9', Pressed);
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_10: // Notifications sent by 'Buttonp'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                //GUI_SendKeyMsg('.', Pressed);
                GUI_EndDialog(pMsg->hWin, 1);
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_11: // Notifications sent by 'Buttonok'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_3);
                if (dialogType == TEMP_TYPE)
                    _dispValue = EDIT_GetFloatValue(hItem);
                else if (dialogType == O2_TYPE)
                    _dispValue2 = EDIT_GetFloatValue(hItem);
                else if (dialogType == CO2_TYPE)
                    _dispValue3 = EDIT_GetFloatValue(hItem);
                _dialogDispMessage.Data.v = dialogType;
                _dialogDispMessage.MsgId = MY_MESSAGE_DISP_TYPE;
                _dialogDispMessage.hWinSrc = pMsg->hWin;
                _dialogDispMessage.hWin = _hWin;
                WM_SendMessage(_hWin, &_dialogDispMessage);
                GUI_EndDialog(pMsg->hWin, 0);

                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
        case ID_BUTTON_12: // Notifications sent by 'Buttonrst'
            switch (NCode) {
            case WM_NOTIFICATION_CLICKED:
                // USER START (Optionally insert code for reacting on notification message)
                // USER END
                break;
            case WM_NOTIFICATION_RELEASED:
                // USER START (Optionally insert code for reacting on notification message)
                GUI_SendKeyMsg(0x08, Pressed);
                // USER END
                break;
                // USER START (Optionally insert additional code for further notification handling)
                // USER END
            }
            break;
            // USER START (Optionally insert additional code for further Ids)
            // USER END
        }
        break;
    // USER START (Optionally insert additional message handling)
    // USER END
    default:
        WM_DefaultProc(pMsg);
        break;
    }
}



/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       CreateWindow
*/

WM_HWIN CreateWindow(void) {
    WM_HWIN hWin;

    hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
    return hWin;
}

/*********************************************************************
*
*       CreateSubWindow
*/

WM_HWIN CreateSubWindow(GUI_HWIN hParent) {
    WM_HWIN hWin;

    hWin = GUI_CreateDialogBox(_aSubDialogCreate, GUI_COUNTOF(_aSubDialogCreate), _cbSubDialog, hParent, 0, 0);
    return hWin;
}



// USER START (Optionally insert additional public code)



void gui_init(void) {
    WM_SetCreateFlags(WM_CF_MEMDEV);
    WM_MOTION_Enable(1);
    WM_MULTIBUF_Enable(1);
    GUI_Init();
    GUI_UC_SetEncodeUTF8(); // Enable UTF8 decoding
    //
    // Set a callback for the background window
    //
    //WM_SetCallback(WM_HBKWIN, _cbBk);
    _hWin = CreateWindow();

}

void gui_loop(void) {
    GUI_Delay(50);
    u32 min, sec;

    disp_text_item = WM_GetDialogItem(_hWin, ID_TEXT_5);
    get_show_time(&dt3, &min, &sec);
    sprintf(disp_buf, "%02d:%02d", min, sec);
    TEXT_SetText(disp_text_item, disp_buf);

    disp_text_item = WM_GetDialogItem(_hWin, ID_TEXT_6);
    get_show_time(&dt2, &min, &sec);
    sprintf(disp_buf, "%02d:%02d", min, sec);
    TEXT_SetText(disp_text_item, disp_buf);

    disp_text_item = WM_GetDialogItem(_hWin, ID_EDIT_0);
    sprintf(disp_buf, "%.1f\xe2\x84\x83", temp_struct.real_temp);
    EDIT_SetText(disp_text_item, disp_buf);

    disp_text_item = WM_GetDialogItem(_hWin, ID_EDIT_1);
    sprintf(disp_buf, "%.1f%%", o2_struct.real_temp);
    EDIT_SetText(disp_text_item, disp_buf);

    disp_text_item = WM_GetDialogItem(_hWin, ID_EDIT_2);
    sprintf(disp_buf, "%.1f%%", co2_struct.real_temp);
    EDIT_SetText(disp_text_item, disp_buf);


    //disp_text_item = WM_GetDialogItem(_hWin, ID_TEXT_7);
    //sprintf(disp_buf, "%.1f s", (float)gui_time2_count / 1000);
    //TEXT_SetText(disp_text_item, disp_buf);

    //disp_text_item = WM_GetDialogItem(_hWin, ID_TEXT_8);
    //sprintf(disp_buf, "%.1f s", (float)gui_time3_count / 1000);
    //TEXT_SetText(disp_text_item, disp_buf);

    //disp_text_item = WM_GetDialogItem(_hWin, ID_TEXT_5);
    //sprintf(disp_buf, "%.2f", expect_temp);
    //TEXT_SetText(disp_text_item, disp_buf);

    //disp_text_item = WM_GetDialogItem(_hWin, ID_TEXT_6);
    //sprintf(disp_buf, "%.2f", real_temp);
    //TEXT_SetText(disp_text_item, disp_buf);
}
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {

    gui_init();
    //
    // Stay alive loop
    //
    while (1) {
        gui_loop();
    }
}

// USER END

/*************************** End of file ****************************/
